import { PickedObject } from '@amcax/base';
import { Matrix4 } from 'three-legacy';
import { refDocNodes } from '../../../../../pages/product-support/assembly-funcs';
import { PickedProduct } from '../../../../../common/components/pick-input/pick-product';

export function revertLastMatrix4(
  dxid: string,
  pickedNode: PickedProduct | PickedObject,
) {
  const lastMatrix = refDocNodes.get(dxid)?.matrix4Array?.at(-1);

  if (lastMatrix) {
    pickedNode.applyMatrix4(new Matrix4().copy(lastMatrix).invert());
  }
}
